package grabbing.ticket.business.api;

import grabbing.ticket.business.service.TicketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 抢票
 *
 * @author lcf
 */
@RequestMapping("/ticket")
@RestController
public class TicketHttp{

    @Autowired
    private TicketService ticketService;

    /**
     * 初始化总票数
     */
    @PostMapping("/init/{num}")
    public String initStore(@PathVariable int num) {
        ticketService.initStore(num);
        return "ok";
    }

    /**
     * 启动消费者
     */
    @PostMapping("/consumer")
    public String startConsumer() {
        ticketService.startConsumer();
        return "ok";
    }

    /**
     * 抢票
     */
    @GetMapping("/ticket/{userId}/{num}")
    public String getTicket(@PathVariable int userId, @PathVariable int num) {
        ticketService.getTicket(userId, num);
        return "ok";
    }

    /**
     * 获取剩余总票数
     */
    @GetMapping("/total")
    public Integer getTotal() {
        return ticketService.getTotal();
    }

    /**
     * 测试抢票
     */
    @GetMapping("/rush/{num}")
    public void testRush(@PathVariable int num) {
        ticketService.testRush(num);
    }
}
